using System.Linq;
using System.Collections.Generic;

namespace FirstUniqueCharacterinaString
{
    public class Solution
    {
        public int FirstUniqChar(string s)
        {
            var dic = new Dictionary<char, int[]>();
            for (var i = 0; i < s.Length; i++)
            {
                if (dic.ContainsKey(s[i]))
                {
                    dic[s[i]][1]++;
                }
                else
                {
                    dic.Add(s[i], new int[] { i, 1 });
                }
            }

            var first = dic.Values.Where(v => v[1] == 1);

            return first.Count() == 0 ? -1 : first.First()[0];
        }
    }
}